﻿using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using IDAL;
using Model;

namespace DAL
{
    public class TProductType : BaseRepository<TProductTypeInfo>, ITProductType
    {
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPEID = "@ProductTypeID";
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPENAME = "@ProductTypeName";
        private const string PARM_TPRODUCTTYPE_PRODUCTTYPESERIALID = "@ProductTypeSerialID";

        #region 数据检索部分
        public IList<TProductTypeInfo> LoadEntities()
        {
            return ExcuteSqlToGetEntities("TProductType_select");
        }

        /// <summary>
        /// Get an individual category based on a provided id
        /// </summary>
        /// <param name="categoryId">Category id</param>
        /// <returns>Details about the Category</returns>
        public TProductTypeInfo LoadEntity<T1>(T1 productTypeId)
        {
            SqlParameter parm = GetParameter();
            //Bind the parameter
            parm.Value = productTypeId;
            return ExcuteSqlToGetEntity("TProductType_selectbyID", parm);
        }
        #endregion

        #region 重写基类部分
        //-------------------------------------重写超类基础操作---------------------------------------------------------

        public override TProductTypeInfo GetEntityRecord(SqlDataReader rdr)
        {
            TProductTypeInfo pro = new TProductTypeInfo { ProductTypeID = rdr.GetValue(0).ToString(), ProductTypeName = rdr.GetValue(1).ToString(), ProductTypeSerialID = rdr.GetValue(2).ToString() };
            return pro;
        }

        public override TProductTypeInfo GetEntityRecord()
        {
            TProductTypeInfo pro = new TProductTypeInfo();
            return pro;
        }

        public override string GetInsertsp()
        {
            return "TProductType_Insert";
        }

        public override string GetUpdatesp()
        {
            return "TProductType_Update";
        }

        public override string GetDeletesp()
        {
            return "TProductType_Delete";
        }

        public override SqlParameter GetParameter()
        {
            SqlParameter Parm = new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEID, SqlDbType.NVarChar, 50);
            return Parm;
        }

        public override SqlParameter[] GetParameters()
        {
            SqlParameter[] parms = null;
            parms = new SqlParameter[]
                {
					new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPEID, SqlDbType.NVarChar, 50),
					new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPENAME, SqlDbType.NVarChar, 50),
                    new SqlParameter(PARM_TPRODUCTTYPE_PRODUCTTYPESERIALID, SqlDbType.NVarChar, 50),
                };
            return parms;
        }

        public override void SetParameters(TProductTypeInfo productType, params SqlParameter[] Parms)
        {
            Parms[0].Value = productType.ProductTypeID;
            Parms[1].Value = productType.ProductTypeName;
            Parms[2].Value = productType.ProductTypeSerialID;
        }
        #endregion
    }
}
